package com.lijin.converter;

import com.lijin.converter.base.BaseConvert;
import com.lijin.domain.dto.LotteryInformationDto;
import com.lijin.domain.entity.LotteryInformation;
import org.springframework.stereotype.Service;

/**
 * Created by gold-jx on 2017/12/8.
 */
@Service
public class LotteryInformationConverter implements BaseConvert<LotteryInformation,LotteryInformationDto> {

    @Override
    public LotteryInformationDto convertToDto(LotteryInformation lotteryInformation) {
        if(lotteryInformation==null){
            return null;
        }
        return copyToDto(lotteryInformation);
    }

    @Override
    public LotteryInformation convertToEntity(LotteryInformationDto lotteryInformationDto) {
        if(lotteryInformationDto==null) {
            return null;
        }
        return copyToEntity(lotteryInformationDto);
    }

    /**
     * dto转成entity
     * @param lid
     * @return
     */
    private static LotteryInformation copyToEntity(LotteryInformationDto lid){
        LotteryInformation li=new LotteryInformation();
        li.setId(lid.getId());
        li.setLotteryCode(lid.getLotteryCode());
        li.setLotteryExpect(lid.getLotteryExpect());
        li.setOpenCode(lid.getOpenCode());
        li.setOpenTime(lid.getOpenTime());
        li.setCreateTime(lid.getCreateTime());
        li.setState(lid.getState());
        li.setVersion(lid.getVersion());
        li.setSource(lid.getSource());
        return li;
    }

    /**
     * entity转成dto
     * @param li
     * @return
     */
    private static LotteryInformationDto copyToDto(LotteryInformation li){
        LotteryInformationDto lid=new LotteryInformationDto();
        lid.setId(li.getId());
        lid.setLotteryCode(li.getLotteryCode());
        lid.setLotteryExpect(li.getLotteryExpect());
        lid.setOpenCode(li.getOpenCode());
        lid.setOpenTime(li.getOpenTime());
        lid.setCreateTime(li.getCreateTime());
        lid.setState(li.getState());
        lid.setVersion(li.getVersion());
        lid.setSource(li.getSource());
        return lid;
    }
}
